<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增用户</title>
    <script src="js/vue.min.js"></script>
    <script src="js/axios.min.js"></script>
</head>
<body>
<div id="app">
    <table border="1" style="margin: 0 auto;width: 300px">
        <tr>
            <th colspan="2">新增用户</th>
        </tr>
        <tr>
            <td>姓名：</td>
            <td><input v-model="user.name" type="text"></td>
        </tr>
        <tr>
            <td>年龄：</td>
            <td><input v-model="user.age" type="text"></td>
        </tr>
        <tr>
            <td colspan="2">
                <button @click="addUser" type="button">新增</button>
            </td>
        </tr>
    </table>

</div>

<script>
    //创建vue
    var vue = new Vue({
        el: "#app",
        data: {
            user: {
                name: "",
                age: ""
            }
        },
        methods: {
            addUser: function () {
                //发送请求，提交数据给后端
                axios.post("/user/add",vue.user).then(function (res){
                    if(res.data.code===200){
                        alert("新增用户成功");
                        //刷新页面
                        location.reload();
                    }else{
                        alert(res.data.message);
                    }

                })
            }
        }
    })

</script>
</body>
</html>
